<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title></title>
<%@ include file="/WEB-INF/views/include/srceasyui.jsp"%>
<script src="${ctx}/static/plugins/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
	<script src="${ctx}/static/plugins/easyui/common/index.js" type="text/javascript"></script>

</head>
<body class="easyui-layout" style="font-family: '微软雅黑'">
	<div data-options="region:'center',split:true,border:false,title:'${oi.orderSn} ---- 运单列表'">
		<div id="tb" style="padding:5px;height:auto">
			<div>
					<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="add();">添加</a>
					<span class="toolbar-item dialog-tool-separator"></span>
					<a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" data-options="disabled:false"  onclick="del()">删除</a>
					<span class="toolbar-item dialog-tool-separator"></span>
					<a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="upd()">修改</a>
			</div>

		</div>
		<table id="dg"></table>
	</div>

	<div data-options="region:'east',split:true,border:false,title:'订单商品列表'" style="width: 425px">

		<table id="deliveryDg"></table>
	</div>

	<div id="dlg"></div>
	<div id="dlgview"></div>
<script type="text/javascript">
var d;
var dview;
var dg;
var deliveryDg;
$(function(){   
	dg=$('#dg').datagrid({    
	method: "get",
    // url:'${ctx}/business/seller/json?filter_EQR_sellerStatus=0',
	url:'${ctx}/business/order/deliveryorderlistjson/${oi.orderId}',
    fit : true,
	fitColumns : true,
	border : false,
	striped:true,
	idField : 'id',
	pagination:true,
	rownumbers:true,
	pageNumber:1,
	pageSize : 20,
	pageList : [ 10, 20, 30, 40, 50 ],
	singleSelect:true,
    columns:[[    
		{field:'deliveryId',title:'id', hidden: true},
		{field:'expressName',title:'快递名称',width:100},
		{field:'deliverySn',title:'发货序号',width:100},
		{field:'addTime',title:'发货时间',width:100},
		{field:'_opt', title:'操作', width:80,
			formatter: function(value, rec) {
				return '<a href="#" onclick="' + 'openDialog(' + rec.deliveryId + ',\'' + rec.expressName + '\',\'' + rec.deliverySn + '\')">查看</a>';
			}
		}

    ]],
    enableHeaderClickMenu: false,
    enableHeaderContextMenu: false,
    enableRowContextMenu: false,
    toolbar:'#tb'
	});

	deliveryDg=$('#deliveryDg').datagrid({
		method: "get",
		// url:'${ctx}/business/seller/json?filter_EQR_sellerStatus=0',
		url:'${ctx}/business/order/goodsjson/${oi.orderId}',
		fit : true,
		fitColumns : true,
		border : false,
		striped:true,
		idField : 'id',
		pagination:true,
		rownumbers:true,
		pageNumber:1,
		pageSize : 20,
		pageList : [ 10, 20, 30, 40, 50 ],
		singleSelect:true,
		columns:[[
			{field:'recId',title:'id', hidden: true},
			{field:'goodsName',title:'商品名称',width:100},
			{field:'goodsPrice',title:'订单中价格',width:100},
			{field:'goodsNumber',title:'订单中数量',width:100},
			{field:'speNote',title:'特产备注',width:100}
		]],
		enableHeaderClickMenu: false,
		enableHeaderContextMenu: false,
		enableRowContextMenu: false
	});
});

function openDialog(deliveryId, expressName, deliverySn) {
	// parent.mainpage.mainTabs.addModule('运单信息','${ctx}/business/order/viewdelivery/'+deliveryId, 'icon-hamburg-settings')

	dview=$("#dlgview").dialog({
		title: '查看运单',
		width: 800,
		height: 450,
		href:'${ctx}/business/order/viewdelivery/'+deliveryId,
		queryParams: { deliveryId: deliveryId, expressName: expressName, deliverySn: deliverySn },
		maximizable:true,
		modal:true,
		buttons:[{
			text:'取消',
			handler:function(){
				dview.panel('close');
			}
		}]
	});
}

//弹窗增加
function add() {
	d=$("#dlg").dialog({
		title: '添加运单',
		width: 800,
		height: 450,
		href:'${ctx}/business/order/createdelivery/${oi.orderId}',
		maximizable:true,
		modal:true,
		buttons:[{
			text:'确认',
			handler:function(){
				// $("#mainform").submit();
				var rows = $('#dg1').datagrid('getRows');
//				alert(rows[0].goodsId + "-" + rows[0].goodsPrice + "-" + rows[0].goodsNumber);
//				alert(JSON.stringify(rows));

				var orderId = ${oi.orderId};
				var expressName = $('#expressName').val();
				var deliverySn = $('#deliverySn').val();

				var ob = {};
				ob.orderId = orderId;
				ob.expressName = expressName;
				ob.deliverySn = deliverySn;
				ob.items = rows;

				if (!check()) {
					return;
				}

				$.ajax({
					url : "${ctx}/business/order/adddeliveryForm",
					type : 'POST',
					data : JSON.stringify(ob),
					dataType : 'json',
					contentType : 'application/json',
					success : function(data, status, xhr) {
						d.panel('close');
						dg.datagrid('reload');
					},
					Error : function(xhr, error, exception) {
						// handle the error.
						alert(exception.toString());
					}
				});
			}
		},{
			text:'取消',
			handler:function(){
				d.panel('close');
			}
		}]
	});
}
//删除
function del(){
	var row = dg.datagrid('getSelected');
	if(rowIsNull(row)) return;
	parent.$.messager.confirm('提示', '删除后无法恢复您确定要删除？', function(data){
		if (data){
			$.ajax({
				type:'get',
				url:"${ctx}/business/order/delete/"+row.deliveryId,
				success: function(data){
					if(successTip(data,dg))
						dg.datagrid('reload');
				}
			});
			//dg.datagrid('reload'); //grid移除一行,不需要再刷新
		}
	});

}

</script>
</body>
</html>